package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.DoctorMapper;
import com.aaa.hospital.pojo.domain.*;
import com.aaa.hospital.pojo.query.DoctorQuery;
import com.aaa.hospital.pojo.vo.DoctorVO;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.DoctorService;
import com.aaa.hospital.util.DateUtil;
import com.alibaba.excel.util.CollectionUtils;
import com.aliyuncs.ram.model.v20150501.GetUserResponse;
import org.aspectj.weaver.ast.Var;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSourceType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author ZQ on 2022/1/9
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;
    @Override
    public AjaxResult doctorList() {

        List<Emp> emps = doctorMapper.doctorsList();
        if (emps == null){
            return AjaxResult.fail();
        }
        return AjaxResult.success(emps);
    }

    @Override
    public AjaxResult doctorsQuery(DoctorQuery doctorQuery) {
        List<Emp> doctors = doctorMapper.doctorsQuery(doctorQuery);
        long l = doctorMapper.queryDoctrsTotal(doctorQuery);
        HashMap<Object,Object> map = new HashMap<>();

        map.put("currentData",doctors);
        map.put("totalCount",l);
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult getKes() {
        List<Kes> kes = doctorMapper.getKes();

        return AjaxResult.success(kes);
    }

    @Override
    public AjaxResult getPost() {

        List<Post> posts = doctorMapper.getPost();
        return AjaxResult.success(posts);
    }

    @Override
    public AjaxResult getRole() {
        List<Role> roles = doctorMapper.getRole();
        return AjaxResult.success(roles);
    }

    @Override
    public AjaxResult addDoctor(DoctorVO doctorVO) {
        String stringDate = DateUtil.getStringDate();
        //获取当前手机号  因为手机号独一无二 第一手机号查重
        String telephone = doctorVO.getTelephone();

        int phone = doctorMapper.listTelephone(telephone);
        System.out.println(phone+"------------");
//            if (phone.equals(telephone)) {
//                return AjaxResult.fail("已有此手机号，请仔细查看");
//            }
        if (phone == 0) {
            doctorMapper.addDoctor(doctorVO);

            int id = doctorMapper.getTelePhone(telephone);
            String dayDate = DateUtil.getStringDate();
            int i = doctorMapper.addshift(dayDate,id);

            return AjaxResult.success(i);

        } else {
            return AjaxResult.fail("已有此手机号，请仔细查看");
        }


    }

    @Override
    public AjaxResult deleteDoctor(Integer id) {
        int i=doctorMapper.deleteDoctor(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult getDoctor(Integer id) {
        DoctorVO i = doctorMapper.getDoctor(id);
        return AjaxResult.success(i);
    }

    @Override
    public AjaxResult updateDoctor(DoctorVO doctorVO) {
        int i = doctorMapper.updateDoctor(doctorVO);

        return AjaxResult.success(i);
    }

    @Override
    public AjaxResult doctorResume(Integer id) {
        List<Emp> i =  doctorMapper.doctorResume(id);
        if (i.isEmpty()) {
            return AjaxResult.fail();
        }


        return AjaxResult.success(i);
    }
}
